package cn.blog.utils;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.core.userdetails.UserDetailsService;
import org.springframework.stereotype.Component;

import cn.blog.dto.LoginUser;
import cn.blog.service.TokenService;

/**
 * 刷新redis用户信息缓存
 * 
 * @author 偶尔有点困
 * @date 2018年5月19日
 */
@Component
public class RefreshUserInfo {

	@Autowired
	private UserDetailsService userDetailsService;

	@Autowired
	private TokenService tokenService;

	public void refresh() {
		LoginUser loginUser = UserUtil.getCurrentUser();
		String token = loginUser.getToken();
		loginUser = (LoginUser) userDetailsService.loadUserByUsername(loginUser.getUsername());
		loginUser.setToken(token);
		tokenService.refresh(loginUser);
	}
}
